<?php

function t2p_encrypt($text_to_send) {
    $reqSalt = rand(100000, 999999);
    return t2p_salt_data($text_to_send, $reqSalt);
}

function t2p_salt_data($req, $salt) {
    $md5 = md5($req . $salt);
    $string = base64_encode(gzcompress($req));
    $partSize = floor(strlen($string) / 4);
    return urlencode(base64_encode(gzcompress(strrev(substr($string, $partSize * 1, $partSize)) . substr($string, 0, $partSize) . strrev(substr($string, $partSize * 2, $partSize)) . "&" . $salt . "_" . substr($string, $partSize * 3, strlen($string) - $partSize * 3) . "_" . $md5)));
}

function t2p_checkchannel($req) {
    $server_output = array();
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "http://test-api.ibaht.com/2bsimple/channel.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('check' => $req)));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = explode("&", $result);

    return $result;
}

?>